package com.itheima.app.controller;

import com.itheima.app.manager.VideoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author zsk
 * @create 2022-03-23-16:02
 */
@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;


    //分页查询小视频列表
    @GetMapping("/smallVideos")
    public ResponseEntity findVideoByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
    ){
        //调用manager
        return videoManager.findVideoByPage(pageNum,pageSize);

    }


    //发布视频
    @PostMapping("/smallVideos")
    public void saveVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {

        //调用manager
        //videoThumbnail视频封面
        //videoFile：视频内容
        videoManager.saveVideo(videoThumbnail,videoFile);

    }


    //关注用户
    @PostMapping("/smallVideos/{focusUserId}/userFocus")
    public void saveFocus(@PathVariable Long focusUserId){

        //调用manager
        videoManager.saveFocus(focusUserId);//传递小视频用户id
    }

    //取消关注
    @PostMapping("/smallVideos/{focusUserId}/userUnFocus")
    public void userUnFocus(@PathVariable Long focusUserId){

        //调用manager
        videoManager.userUnFocus(focusUserId);

    }



}
